using DevExpress.LookAndFeel;
using DevExpress.Skins;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraWizard;
using Microsoft.Win32;
using Extra.Data.Extra.Class;
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using APP.HELPER.Data.Helper;
using APP.HELPER.Utils.OSInfo;
using APP.HELPER.Utils;
using APP.HELPER.Utils.UI;
namespace Extra.Data
{
    public class xfmFirstRunConfig : XtraForm
    {
        private bool _exit;
        private int _status = 0;
        private LoadingCircle autoCreate;
        private SimpleButton btnConnect;
        private SimpleButton btnConnectDatabase;
        private SimpleButton btnDatabase;
        private SimpleButton btnPath;
        private SimpleButton btnVideo;
        private ComboBoxEdit cbxDatabase;
        private ComboBoxEdit cbxServer;
        private CheckEdit checkEdit2;
        private CheckEdit checkEdit3;
        private CheckEdit cheExample;
        private CheckBox chxAuto;
        private CheckBox chxClient;
        private CheckBox chxManual;
        private CheckBox chxPerfect;
        private IContainer components = null;
        private LabelControl labelControl1;
        private LabelControl labelControl2;
        private LabelControl labelControl3;
        private LabelControl labelControl4;
        private LabelControl labelControl5;
        private LabelControl lblDatabase;
        private LabelControl lblServer;
        private LabelControl lblSqlpassword;
        private LabelControl lblSqlusername;
        private RadioGroup rdgAuthentication;
        private TextEdit teLogin;
        private TextEdit tePassword;
        private TextEdit txtDatabase;
        private TextEdit txtPath;
        private WizardControl wcFirstRun;
        private DevExpress.XtraWizard.WizardPage wpAuto;
        private DevExpress.XtraWizard.WizardPage wpClient;
        private CompletionWizardPage wpComplete;
        private DevExpress.XtraWizard.WizardPage wpCreate;
        private DevExpress.XtraWizard.WizardPage wpLogin;
        private WelcomeWizardPage wpSelects;

        public xfmFirstRunConfig()
        {
            this.InitializeComponent();
            this.cbxServer.Text = Environment.MachineName.ToUpper() + @"\PERFECT";
            this.txtDatabase.Text = "ERP.PMQLNS";
            this.txtPath.Text = DataController.DataMaker.GetLastDrive() + @"\Database\Perfect Software\" + APP.HELPER.Utils.AssemblyHelper.AssemblyTradeMark;
            this.teLogin.Text = "sa";
            this.tePassword.Text = "perfect";
            this._exit = true;
            if ((OSInfo.GetOS() == OSInfo.EnumOS.Windows_Vista) | (OSInfo.GetOS() == OSInfo.EnumOS.Windows_7))
            {
                this.rdgAuthentication.SelectedIndex = 1;
            }
        }

        private void Auto()
        {
            this.wcFirstRun.SelectedPage = this.wpClient;
            this.wpAuto.AllowBack = false;
            this.wpAuto.AllowNext = false;
            this.wpAuto.AllowCancel = false;
            this.autoCreate.Active = true;
            MyLogon myLogon = new MyLogon();
            myLogon.Fail += new MyLogon.FailEventHander(this.myLogon_Fail);
            myLogon.Error += new MyLogon.ErrorEventHander(this.myLogon_Error);
            myLogon.Finish += new MyLogon.FinishEventHander(this.myLogon_Finish);
            myLogon.First += new MyLogon.FirstEventHander(this.MyLogonFirst);
            bool authen = this.rdgAuthentication.SelectedIndex == 0;
            new Thread(() => myLogon.Execute2(this.cbxServer.Text, this.txtDatabase.Text, this.teLogin.Text, this.tePassword.Text, authen, this.txtPath.Text, this.cheExample.Checked)).Start();
        }

        private void btnConnect_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            this.btnConnect.Enabled = false;
            if (this.IsConnecttion(this.cbxServer.Text, "master", this.teLogin.Text, this.tePassword.Text))
            {
                XtraMessageBox.Show("Kết nối đến m\x00e1y chủ th\x00e0nh c\x00f4ng!");
            }
            this.btnConnect.Enabled = true;
            Cursor.Current = Cursors.Default;
        }

        private void btnConnectDatabase_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            this.btnConnect.Enabled = false;
            if (this.cbxDatabase.Text == "")
            {
                XtraMessageBox.Show("Cở Sở Dữ Liệu chưa x\x00e1c định.", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.IsConnecttion(this.cbxServer.Text, this.cbxDatabase.Text, this.teLogin.Text, this.tePassword.Text))
            {
                XtraMessageBox.Show("Kết nối đến m\x00e1y chủ th\x00e0nh c\x00f4ng!");
            }
            this.btnConnect.Enabled = true;
            Cursor.Current = Cursors.Default;
        }

        private void btnDatabase_Click(object sender, EventArgs e)
        {
            base.Enabled = false;
            try
            {
                FileInfo info = new FileInfo(Application.StartupPath + @"\perfect.data.exe");
                if (info.Exists)
                {
                    Process.Start(info.FullName);
                    Environment.Exit(0);
                }
                else
                {
                    XtraMessageBox.Show("Kh\x00f4ng t\x00ecm thấy tr\x00ecnh Quản L\x00fd Dữ Liệu", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception exception)
            {
                XtraMessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            base.Enabled = true;
        }

        private void btnPath_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.txtPath.Text = dialog.SelectedPath;
            }
        }

        private void btnVideo_Click(object sender, EventArgs e)
        {
            Process.Start("http://www.perfect.com.vn/phan-mem-quan-ly-nhan-su.html");
        }

        private void cbxDatabase_Properties_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            if ((e.Button.Index == 0) && (this.cbxDatabase.Properties.Items.Count == 0))
            {
                Cursor.Current = Cursors.WaitCursor;
                this.cbxDatabase.Enabled = false;
                DataController controller = new DataController();
                DataTable table = (this.rdgAuthentication.SelectedIndex == 0) ? controller.GetDatabase(this.cbxServer.Text) : controller.GetDatabase(this.cbxServer.Text, this.teLogin.Text, this.tePassword.Text);
                if ((table != null) && (table.Rows.Count > 0))
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        this.cbxDatabase.Properties.Items.Add(table.Rows[i][1]);
                    }
                }
                if (this.cbxDatabase.Properties.Items.Count > 0)
                {
                    this.cbxDatabase.SelectedIndex = 0;
                }
                this.cbxDatabase.Enabled = true;
                Cursor.Current = Cursors.Default;
            }
        }

        private void cbxServer_Properties_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            if ((e.Button.Index == 0) && (this.cbxServer.Properties.Items.Count == 0))
            {
                Cursor.Current = Cursors.WaitCursor;
                this.cbxServer.Enabled = false;
                DataTable server = new DataController().GetServer();
                if ((server != null) && (server.Rows.Count > 0))
                {
                    for (int i = 0; i < server.Rows.Count; i++)
                    {
                        this.cbxServer.Properties.Items.Add(server.Rows[i][0]);
                    }
                }
                if (this.cbxServer.Properties.Items.Count > 0)
                {
                    this.cbxServer.SelectedIndex = 0;
                }
                this.cbxServer.Enabled = true;
                Cursor.Current = Cursors.Default;
            }
        }

        private void chxAuto_CheckedChanged(object sender, EventArgs e)
        {
            this.chxAuto.Checked = true;
            this.chxClient.Checked = false;
            this.chxManual.Checked = false;
            this.chxPerfect.Checked = false;
        }

        private void chxAuto_CheckedChanged_1(object sender, EventArgs e)
        {
        }

        private void chxClient_CheckedChanged(object sender, EventArgs e)
        {
            this.chxAuto.Checked = false;
            this.chxClient.Checked = true;
            this.chxManual.Checked = false;
            this.chxPerfect.Checked = false;
        }

        private void chxClient_CheckedChanged_1(object sender, EventArgs e)
        {
        }

        private void chxManual_CheckedChanged(object sender, EventArgs e)
        {
            this.chxAuto.Checked = false;
            this.chxClient.Checked = false;
            this.chxManual.Checked = true;
            this.chxPerfect.Checked = false;
        }

        private void chxManual_CheckedChanged_1(object sender, EventArgs e)
        {
        }

        private void chxPerfect_Click(object sender, EventArgs e)
        {
            this.chxAuto.Checked = false;
            this.chxClient.Checked = false;
            this.chxManual.Checked = false;
            this.chxPerfect.Checked = true;
        }

        private void Demo()
        {
            this.wcFirstRun.SelectedPage = this.wpAuto;
            this.wpAuto.AllowBack = false;
            this.wpAuto.AllowNext = false;
            this.wpAuto.AllowCancel = false;
            this.autoCreate.Active = true;
            if (this.IsConnecttion("http://perfect.com.vn", "HOANHAO.QLNS", "drghy", "thjki@#$%546"))
            {
                this.wcFirstRun.SelectedPage = this.wpComplete;
                this.autoCreate.Active = false;
                this._exit = false;
                if (!Directory.Exists(Application.StartupPath + @"\Layout"))
                {
                    Directory.CreateDirectory(Application.StartupPath + @"\Layout");
                }
                if (!Directory.Exists(Application.StartupPath + @"\Data"))
                {
                    Directory.CreateDirectory(Application.StartupPath + @"\Data");
                }
                SqlHelper helper = new SqlHelper("http://perfect.com.vn", "HOANHAO.QLNS", "drghy", "thjki@#$%546");
                SqlHelper.ConnectString = helper.ConnectionString;
                new MyLogon().SaveConfig(helper.Server, helper.Authentication ? 0 : 1, helper.UserID, helper.Password, helper.Database);
                //new XfmCompany(true, 1).ShowDialog(this);
                //base.Close();
            }
            else
            {
                this.autoCreate.Active = false;
                this.wcFirstRun.SelectedPageIndex = 0;
            }
        }

        private void DisableSQLServerAuthentication(bool disable)
        {
            this.teLogin.Enabled = !disable;
            this.tePassword.Enabled = !disable;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xfmFirstRunConfig));
            SuperToolTip tip = new SuperToolTip();
            ToolTipItem item = new ToolTipItem();
            SerializableAppearanceObject appearance = new SerializableAppearanceObject();
            SuperToolTip tip2 = new SuperToolTip();
            ToolTipItem item2 = new ToolTipItem();
            this.wcFirstRun = new WizardControl();
            this.btnVideo = new SimpleButton();
            this.btnDatabase = new SimpleButton();
            this.wpSelects = new WelcomeWizardPage();
            this.chxPerfect = new CheckBox();
            this.chxManual = new CheckBox();
            this.chxClient = new CheckBox();
            this.labelControl5 = new LabelControl();
            this.chxAuto = new CheckBox();
            this.wpComplete = new CompletionWizardPage();
            this.labelControl3 = new LabelControl();
            this.wpCreate = new DevExpress.XtraWizard.WizardPage();
            this.checkEdit3 = new CheckEdit();
            this.checkEdit2 = new CheckEdit();
            this.cheExample = new CheckEdit();
            this.txtDatabase = new TextEdit();
            this.btnPath = new SimpleButton();
            this.labelControl1 = new LabelControl();
            this.txtPath = new TextEdit();
            this.lblDatabase = new LabelControl();
            this.wpAuto = new DevExpress.XtraWizard.WizardPage();
            this.labelControl2 = new LabelControl();
            this.autoCreate = new LoadingCircle();
            this.wpClient = new DevExpress.XtraWizard.WizardPage();
            this.btnConnectDatabase = new SimpleButton();
            this.cbxDatabase = new ComboBoxEdit();
            this.labelControl4 = new LabelControl();
            this.wpLogin = new DevExpress.XtraWizard.WizardPage();
            this.btnConnect = new SimpleButton();
            this.cbxServer = new ComboBoxEdit();
            this.tePassword = new TextEdit();
            this.teLogin = new TextEdit();
            this.lblSqlpassword = new LabelControl();
            this.lblSqlusername = new LabelControl();
            this.rdgAuthentication = new RadioGroup();
            this.lblServer = new LabelControl();
            this.wcFirstRun.BeginInit();
            this.wcFirstRun.SuspendLayout();
            this.wpSelects.SuspendLayout();
            this.wpComplete.SuspendLayout();
            this.wpCreate.SuspendLayout();
            this.checkEdit3.Properties.BeginInit();
            this.checkEdit2.Properties.BeginInit();
            this.cheExample.Properties.BeginInit();
            this.txtDatabase.Properties.BeginInit();
            this.txtPath.Properties.BeginInit();
            this.wpAuto.SuspendLayout();
            this.wpClient.SuspendLayout();
            this.cbxDatabase.Properties.BeginInit();
            this.wpLogin.SuspendLayout();
            this.cbxServer.Properties.BeginInit();
            this.tePassword.Properties.BeginInit();
            this.teLogin.Properties.BeginInit();
            this.rdgAuthentication.Properties.BeginInit();
            base.SuspendLayout();
            this.wcFirstRun.CancelText = "Tho\x00e1t";
            this.wcFirstRun.Controls.Add(this.btnVideo);
            this.wcFirstRun.Controls.Add(this.btnDatabase);
            this.wcFirstRun.Controls.Add(this.wpSelects);
            this.wcFirstRun.Controls.Add(this.wpComplete);
            this.wcFirstRun.Controls.Add(this.wpCreate);
            this.wcFirstRun.Controls.Add(this.wpAuto);
            this.wcFirstRun.Controls.Add(this.wpClient);
            this.wcFirstRun.Controls.Add(this.wpLogin);
            this.wcFirstRun.FinishText = "Kết Th\x00fac";
            this.wcFirstRun.HelpButtonCausesValidation = true;
            this.wcFirstRun.HelpText = "&Trợ Gi\x00fap";
            this.wcFirstRun.HelpVisible = true;
            this.wcFirstRun.Name = "wcFirstRun";
            this.wcFirstRun.NextText = "&Tiếp Tục >";
            this.wcFirstRun.Pages.AddRange(new BaseWizardPage[] { this.wpSelects, this.wpLogin, this.wpCreate, this.wpClient, this.wpAuto, this.wpComplete });
            this.wcFirstRun.PreviousText = "< &Trở Lại";
            this.wcFirstRun.Text = "System Config";
            this.wcFirstRun.UseCancelButton = false;
            this.wcFirstRun.WizardStyle = WizardStyle.WizardAero;
            this.wcFirstRun.PrevClick += new WizardCommandButtonClickEventHandler(this.wcFirstRun_PrevClick);
            this.wcFirstRun.SelectedPageChanging += new WizardPageChangingEventHandler(this.wcFirstRun_SelectedPageChanging);
            this.wcFirstRun.SelectedPageChanged += new WizardPageChangedEventHandler(this.wcFirstRun_SelectedPageChanged);
            this.wcFirstRun.NextClick += new WizardCommandButtonClickEventHandler(this.wcFirstRun_NextClick);
            this.wcFirstRun.CancelClick += new CancelEventHandler(this.wcFirstRun_CancelClick);
            this.btnVideo.Location = new Point(400, 6);
            this.btnVideo.Name = "btnVideo";
            this.btnVideo.Size = new Size(0x7b, 0x1b);
            this.btnVideo.TabIndex = 0x16;
            this.btnVideo.Text = "Video Hướng Dẫn";
            this.btnVideo.Click += new EventHandler(this.btnVideo_Click);
            this.btnDatabase.Image = (Image)manager.GetObject("btnDatabase.Image");
            this.btnDatabase.Location = new Point(7, 0x15a);
            this.btnDatabase.Name = "btnDatabase";
            this.btnDatabase.Size = new Size(0x8f, 0x1b);
            item.Text = "Th\x00eam hoặc x\x00f3a Cơ Sở Dữ Liệu";
            tip.Items.Add(item);
            this.btnDatabase.SuperTip = tip;
            this.btnDatabase.TabIndex = 15;
            this.btnDatabase.Text = "Quản L\x00fd Cơ Sở Dữ Liệu";
            this.btnDatabase.Click += new EventHandler(this.btnDatabase_Click);
            this.wpSelects.Controls.Add(this.chxPerfect);
            this.wpSelects.Controls.Add(this.chxManual);
            this.wpSelects.Controls.Add(this.chxClient);
            this.wpSelects.Controls.Add(this.labelControl5);
            this.wpSelects.Controls.Add(this.chxAuto);
            this.wpSelects.Name = "wpSelects";
            this.wpSelects.Size = new Size(0x1dd, 0xdb);
            this.wpSelects.Text = "";
            this.chxPerfect.BackColor = System.Drawing.Color.Transparent;
            this.chxPerfect.Location = new Point(15, 0xad);
            this.chxPerfect.Name = "chxPerfect";
            this.chxPerfect.Size = new Size(0x1ce, 40);
            this.chxPerfect.TabIndex = 5;
            this.chxPerfect.Text = "4. Thiết lập dữ liệu demo của m\x00e1y chủ Ho\x00e0n Hảo (Ch\x00fa \x00fd: m\x00f4i trường internet)\r\n";
            this.chxPerfect.UseCompatibleTextRendering = true;
            this.chxPerfect.UseVisualStyleBackColor = true;
            this.chxPerfect.Visible = false;
            this.chxPerfect.Click += new EventHandler(this.chxPerfect_Click);
            this.chxManual.BackColor = System.Drawing.Color.Transparent;
            this.chxManual.Location = new Point(15, 0x68);
            this.chxManual.Name = "chxManual";
            this.chxManual.Size = new Size(0x1d2, 0x24);
            this.chxManual.TabIndex = 4;
            this.chxManual.Text = "2. Tự thiết lập dữ liệu v\x00e0 hệ thống.";
            this.chxManual.UseCompatibleTextRendering = true;
            this.chxManual.UseVisualStyleBackColor = false;
            this.chxManual.Click += new EventHandler(this.chxManual_CheckedChanged);
            this.chxManual.CheckedChanged += new EventHandler(this.chxManual_CheckedChanged_1);
            this.chxClient.BackColor = System.Drawing.Color.Transparent;
            this.chxClient.Location = new Point(15, 0x89);
            this.chxClient.Name = "chxClient";
            this.chxClient.Size = new Size(0x1d2, 40);
            this.chxClient.TabIndex = 3;
            this.chxClient.Text = "3. Thiết lập m\x00e1y trạm (hoạt động trong m\x00f4i trường mạng LAN, Internet)";
            this.chxClient.UseCompatibleTextRendering = true;
            this.chxClient.UseVisualStyleBackColor = false;
            this.chxClient.Click += new EventHandler(this.chxClient_CheckedChanged);
            this.chxClient.CheckedChanged += new EventHandler(this.chxClient_CheckedChanged_1);
            this.labelControl5.AccessibleRole = AccessibleRole.Alert;
            this.labelControl5.AllowHtmlString = true;
            this.labelControl5.AllowHtmlTextInToolTip = DefaultBoolean.True;
            this.labelControl5.Appearance.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.labelControl5.Appearance.Options.UseFont = true;
            this.labelControl5.Appearance.Options.UseTextOptions = true;
            this.labelControl5.Appearance.TextOptions.HAlignment = HorzAlignment.Center;
            this.labelControl5.Appearance.TextOptions.HotkeyPrefix = HKeyPrefix.Show;
            this.labelControl5.Appearance.TextOptions.Trimming = Trimming.Word;
            this.labelControl5.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.labelControl5.AutoSizeMode = LabelAutoSizeMode.None;
            this.labelControl5.BorderStyle = BorderStyles.NoBorder;
            this.labelControl5.LineOrientation = LabelLineOrientation.Horizontal;
            this.labelControl5.Location = new Point(3, 3);
            this.labelControl5.Name = "labelControl5";
            this.labelControl5.Size = new Size(0x1de, 0x40);
            this.labelControl5.TabIndex = 2;
            this.labelControl5.Text = manager.GetString("labelControl5.Text");
            this.chxAuto.BackColor = System.Drawing.Color.Transparent;
            this.chxAuto.Checked = true;
            this.chxAuto.CheckState = CheckState.Checked;
            this.chxAuto.Location = new Point(15, 0x45);
            this.chxAuto.Name = "chxAuto";
            this.chxAuto.Size = new Size(0x1d2, 0x23);
            this.chxAuto.TabIndex = 0;
            this.chxAuto.Text = "1. Thiết lập cơ sở dữ liệu v\x00e0 hệ thống tự động.";
            this.chxAuto.UseCompatibleTextRendering = true;
            this.chxAuto.UseVisualStyleBackColor = false;
            this.chxAuto.Click += new EventHandler(this.chxAuto_CheckedChanged);
            this.chxAuto.CheckedChanged += new EventHandler(this.chxAuto_CheckedChanged_1);
            this.wpComplete.AllowBack = false;
            this.wpComplete.Controls.Add(this.labelControl3);
            this.wpComplete.Name = "wpComplete";
            this.wpComplete.Size = new Size(0x1dd, 0xdb);
            this.wpComplete.Text = "";
            this.labelControl3.Appearance.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.labelControl3.Appearance.ForeColor = System.Drawing.Color.Gray;
            this.labelControl3.Appearance.Options.UseFont = true;
            this.labelControl3.Appearance.Options.UseForeColor = true;
            this.labelControl3.Appearance.Options.UseTextOptions = true;
            this.labelControl3.Appearance.TextOptions.HAlignment = HorzAlignment.Center;
            this.labelControl3.Appearance.TextOptions.VAlignment = VertAlignment.Top;
            this.labelControl3.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.labelControl3.AutoSizeMode = LabelAutoSizeMode.None;
            this.labelControl3.Location = new Point(0x26, 0x5e);
            this.labelControl3.Name = "labelControl3";
            this.labelControl3.Size = new Size(0x16a, 0x21);
            this.labelControl3.TabIndex = 4;
            this.labelControl3.Text = "Qu\x00e1 tr\x00ecnh cấu h\x00ecnh đ\x00e3 ho\x00e0n tất.\r\nXem hướng dẫn trước khi sử dụng!";
            this.wpCreate.Controls.Add(this.checkEdit3);
            this.wpCreate.Controls.Add(this.checkEdit2);
            this.wpCreate.Controls.Add(this.cheExample);
            this.wpCreate.Controls.Add(this.txtDatabase);
            this.wpCreate.Controls.Add(this.btnPath);
            this.wpCreate.Controls.Add(this.labelControl1);
            this.wpCreate.Controls.Add(this.txtPath);
            this.wpCreate.Controls.Add(this.lblDatabase);
            this.wpCreate.Name = "wpCreate";
            this.wpCreate.Size = new Size(0x1dd, 0xdb);
            this.wpCreate.Text = "Cấu h\x00ecnh cở sở dữ liệu";
            this.checkEdit3.Enabled = false;
            this.checkEdit3.Location = new Point(0x49, 0x9b);
            this.checkEdit3.Name = "checkEdit3";
            this.checkEdit3.Properties.Caption = "Cho ph\x00e9p xuất \x00e2m";
            this.checkEdit3.Size = new Size(0x84, 0x13);
            this.checkEdit3.TabIndex = 50;
            this.checkEdit3.Visible = false;
            this.checkEdit2.Enabled = false;
            this.checkEdit2.Location = new Point(0x49, 0x7b);
            this.checkEdit2.Name = "checkEdit2";
            this.checkEdit2.Properties.Caption = "Quản l\x00fd ph\x00e2n L\x00f4-Serial";
            this.checkEdit2.Size = new Size(0x84, 0x13);
            this.checkEdit2.TabIndex = 0x31;
            this.checkEdit2.Visible = false;
            this.cheExample.EditValue = true;
            this.cheExample.Location = new Point(0x49, 0x5b);
            this.cheExample.Name = "cheExample";
            this.cheExample.Properties.Caption = "C\x00f3 dữ liệu tham khảo";
            this.cheExample.Size = new Size(0x84, 0x13);
            this.cheExample.TabIndex = 0x30;
            this.txtDatabase.Location = new Point(0x49, 3);
            this.txtDatabase.Name = "txtDatabase";
            this.txtDatabase.Size = new Size(0x171, 20);
            this.txtDatabase.TabIndex = 0x2f;
            this.btnPath.Image = (Image)manager.GetObject("btnPath.Image");
            this.btnPath.Location = new Point(0x49, 0x37);
            this.btnPath.Name = "btnPath";
            this.btnPath.Size = new Size(0x6f, 0x1b);
            this.btnPath.TabIndex = 0x2d;
            this.btnPath.Text = "Chọn Đường Dẫn";
            this.btnPath.Click += new EventHandler(this.btnPath_Click);
            this.labelControl1.Location = new Point(4, 0x20);
            this.labelControl1.Name = "labelControl1";
            this.labelControl1.Size = new Size(0x36, 13);
            this.labelControl1.TabIndex = 0x2c;
            this.labelControl1.Text = "Đường dẫn";
            this.txtPath.Location = new Point(0x49, 0x1d);
            this.txtPath.Name = "txtPath";
            this.txtPath.Size = new Size(0x171, 20);
            this.txtPath.TabIndex = 0x2b;
            this.lblDatabase.Location = new Point(2, 6);
            this.lblDatabase.Name = "lblDatabase";
            this.lblDatabase.Size = new Size(0x3e, 13);
            this.lblDatabase.TabIndex = 0x29;
            this.lblDatabase.Text = "Cơ sở dữ liệu";
            this.wpAuto.AllowBack = false;
            this.wpAuto.AllowCancel = false;
            this.wpAuto.AllowNext = false;
            this.wpAuto.Controls.Add(this.labelControl2);
            this.wpAuto.Controls.Add(this.autoCreate);
            this.wpAuto.DescriptionText = "";
            this.wpAuto.Name = "wpAuto";
            this.wpAuto.Size = new Size(0x1dd, 0xdb);
            this.wpAuto.Text = "";
            this.labelControl2.Appearance.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.labelControl2.Appearance.ForeColor = System.Drawing.Color.Gray;
            this.labelControl2.Appearance.Options.UseFont = true;
            this.labelControl2.Appearance.Options.UseForeColor = true;
            this.labelControl2.Appearance.Options.UseTextOptions = true;
            this.labelControl2.Appearance.TextOptions.HAlignment = HorzAlignment.Center;
            this.labelControl2.Appearance.TextOptions.VAlignment = VertAlignment.Top;
            this.labelControl2.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.labelControl2.AutoSizeMode = LabelAutoSizeMode.None;
            this.labelControl2.Location = new Point(0x36, 0x84);
            this.labelControl2.Name = "labelControl2";
            this.labelControl2.Size = new Size(0x16a, 0x2b);
            this.labelControl2.TabIndex = 3;
            this.labelControl2.Text = "Đang Thiết lập hệ thống.\r\nVui l\x00f2ng chờ...!";
            this.autoCreate.Active = false;
            this.autoCreate.BackColor = System.Drawing.Color.Transparent;
            this.autoCreate.Color = System.Drawing.Color.DarkGray;
            this.autoCreate.InnerCircleRadius = 10;
            this.autoCreate.Location = new Point(0xb9, 0x25);
            this.autoCreate.Name = "autoCreate";
            this.autoCreate.NumberSpoke = 0x23;
            this.autoCreate.OuterCircleRadius = 0x23;
            this.autoCreate.RotationSpeed = 100;
            this.autoCreate.Size = new Size(0x5c, 0x4a);
            this.autoCreate.SpokeThickness = 4;
            this.autoCreate.TabIndex = 0;
            this.autoCreate.Text = "loadingCircle1";
            this.wpClient.Controls.Add(this.btnConnectDatabase);
            this.wpClient.Controls.Add(this.cbxDatabase);
            this.wpClient.Controls.Add(this.labelControl4);
            this.wpClient.Name = "wpClient";
            this.wpClient.Size = new Size(0x1dd, 0xdb);
            this.wpClient.Text = "Chọn cơ sở dữ liệu";
            this.btnConnectDatabase.Location = new Point(0x51, 0x1f);
            this.btnConnectDatabase.Name = "btnConnectDatabase";
            this.btnConnectDatabase.Size = new Size(0x4b, 0x17);
            this.btnConnectDatabase.TabIndex = 60;
            this.btnConnectDatabase.Text = "Kiểm Tra";
            this.btnConnectDatabase.Click += new EventHandler(this.btnConnectDatabase_Click);
            this.cbxDatabase.Location = new Point(80, 4);
            this.cbxDatabase.Name = "cbxDatabase";
            this.cbxDatabase.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.cbxDatabase.Properties.ButtonClick += new ButtonPressedEventHandler(this.cbxDatabase_Properties_ButtonClick);
            this.cbxDatabase.Size = new Size(0xcf, 20);
            this.cbxDatabase.TabIndex = 0x39;
            this.labelControl4.Location = new Point(4, 7);
            this.labelControl4.Name = "labelControl4";
            this.labelControl4.Size = new Size(0x43, 13);
            this.labelControl4.TabIndex = 0x38;
            this.labelControl4.Text = "Cở Sở Dữ Liệu";
            this.wpLogin.Controls.Add(this.btnConnect);
            this.wpLogin.Controls.Add(this.cbxServer);
            this.wpLogin.Controls.Add(this.tePassword);
            this.wpLogin.Controls.Add(this.teLogin);
            this.wpLogin.Controls.Add(this.lblSqlpassword);
            this.wpLogin.Controls.Add(this.lblSqlusername);
            this.wpLogin.Controls.Add(this.rdgAuthentication);
            this.wpLogin.Controls.Add(this.lblServer);
            this.wpLogin.Name = "wpLogin";
            this.wpLogin.Size = new Size(0x1dd, 0xdb);
            this.wpLogin.Text = "Chọn m\x00e1y chủ";
            this.btnConnect.Location = new Point(0x48, 0x71);
            this.btnConnect.Name = "btnConnect";
            this.btnConnect.Size = new Size(90, 0x17);
            this.btnConnect.TabIndex = 0x3d;
            this.btnConnect.Text = "Kiểm Tra";
            this.btnConnect.Click += new EventHandler(this.btnConnect_Click);
            this.cbxServer.EditValue = @"(Local)\PERFECT";
            this.cbxServer.Location = new Point(0x48, 7);
            this.cbxServer.Name = "cbxServer";
            appearance.ForeColor = System.Drawing.Color.Transparent;
            appearance.Options.UseForeColor = true;
            this.cbxServer.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo), new EditorButton(ButtonPredefines.Glyph, "", -1, true, true, false, ImageLocation.MiddleCenter, (Image)manager.GetObject("cbxServer.Properties.Buttons"), new KeyShortcut(Keys.None), appearance, "", null, null, false) });
            this.cbxServer.Properties.ButtonClick += new ButtonPressedEventHandler(this.cbxServer_Properties_ButtonClick);
            this.cbxServer.Size = new Size(0x10f, 0x16);
            tip2.AllowHtmlText = DefaultBoolean.True;
            item2.Text = "Bạn c\x00f3 thể g\x00f5 trực tiếp hoặc chọn từ danh s\x00e1ch. <br>Ch\x00fa \x00fd: m\x00e1y chủ mặc định l\x00e0 T\x00caNM\x00c1YCHỦ\\PERFECT";
            tip2.Items.Add(item2);
            this.cbxServer.SuperTip = tip2;
            this.cbxServer.TabIndex = 0x2f;
            this.tePassword.EditValue = "perfect";
            this.tePassword.Enabled = false;
            this.tePassword.Location = new Point(0x48, 0x57);
            this.tePassword.Name = "tePassword";
            this.tePassword.Properties.PasswordChar = '*';
            this.tePassword.Size = new Size(0x10f, 20);
            this.tePassword.TabIndex = 0x2c;
            this.teLogin.EditValue = "sa";
            this.teLogin.Enabled = false;
            this.teLogin.Location = new Point(0x48, 0x3f);
            this.teLogin.Name = "teLogin";
            this.teLogin.Size = new Size(0x10f, 20);
            this.teLogin.TabIndex = 0x2b;
            this.lblSqlpassword.Location = new Point(7, 90);
            this.lblSqlpassword.Name = "lblSqlpassword";
            this.lblSqlpassword.Size = new Size(0x2d, 13);
            this.lblSqlpassword.TabIndex = 0x2e;
            this.lblSqlpassword.Text = "Mật Khẩu";
            this.lblSqlusername.Location = new Point(7, 0x42);
            this.lblSqlusername.Name = "lblSqlusername";
            this.lblSqlusername.Size = new Size(0x2f, 13);
            this.lblSqlusername.TabIndex = 0x2d;
            this.lblSqlusername.Text = "T\x00e0i Khoản";
            this.rdgAuthentication.AutoSizeInLayoutControl = true;
            this.rdgAuthentication.EditValue = 0;
            this.rdgAuthentication.Location = new Point(0x48, 0x21);
            this.rdgAuthentication.Name = "rdgAuthentication";
            this.rdgAuthentication.Properties.Appearance.BackColor = System.Drawing.Color.Transparent;
            this.rdgAuthentication.Properties.Appearance.Options.UseBackColor = true;
            this.rdgAuthentication.Properties.Columns = 2;
            this.rdgAuthentication.Properties.Items.AddRange(new RadioGroupItem[] { new RadioGroupItem(0, "T\x00e0i Khoản Windows"), new RadioGroupItem(1, "T\x00e0i Khoản SQL Server") });
            this.rdgAuthentication.Size = new Size(0x10f, 0x19);
            this.rdgAuthentication.TabIndex = 0x2a;
            this.rdgAuthentication.SelectedIndexChanged += new EventHandler(this.rdgAuthentication_SelectedIndexChanged);
            this.lblServer.Location = new Point(7, 10);
            this.lblServer.Name = "lblServer";
            this.lblServer.Size = new Size(0x2a, 13);
            this.lblServer.TabIndex = 0x29;
            this.lblServer.Text = "M\x00e1y Chủ";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x219, 0x17d);
            base.Controls.Add(this.wcFirstRun);
            this.DoubleBuffered = true;
            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.Icon = (Icon)manager.GetObject("$this.Icon");
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "xfmFirstRunConfig";
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "Cấu H\x00ecnh";
            base.Load += new EventHandler(this.xfmFirstRunConfig_Load);
            base.FormClosing += new FormClosingEventHandler(this.xfmFirstRunConfig_FormClosing);
            this.wcFirstRun.EndInit();
            this.wcFirstRun.ResumeLayout(false);
            this.wpSelects.ResumeLayout(false);
            this.wpComplete.ResumeLayout(false);
            this.wpCreate.ResumeLayout(false);
            this.wpCreate.PerformLayout();
            this.checkEdit3.Properties.EndInit();
            this.checkEdit2.Properties.EndInit();
            this.cheExample.Properties.EndInit();
            this.txtDatabase.Properties.EndInit();
            this.txtPath.Properties.EndInit();
            this.wpAuto.ResumeLayout(false);
            this.wpClient.ResumeLayout(false);
            this.wpClient.PerformLayout();
            this.cbxDatabase.Properties.EndInit();
            this.wpLogin.ResumeLayout(false);
            this.wpLogin.PerformLayout();
            this.cbxServer.Properties.EndInit();
            this.tePassword.Properties.EndInit();
            this.teLogin.Properties.EndInit();
            this.rdgAuthentication.Properties.EndInit();
            base.ResumeLayout(false);
        }

        private bool IsConnecttion(string server, string database, string user, string pass)
        {
            SqlHelper helper = new SqlHelper(server, database, user, pass, this.rdgAuthentication.SelectedIndex == 0);
            if (!helper.Check())
            {
                XtraMessageBox.Show("Kh\x00f4ng thể kết nối đến m\x00e1y chủ." + helper.Result, "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return false;
            }
            return true;
        }

        public bool IsExpressInstalled()
        {
            using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Microsoft SQL Server\", false))
            {
                if (key == null)
                {
                    return false;
                }
                string[] subKeyNames = key.GetSubKeyNames();
                if (subKeyNames.Length == 0)
                {
                    return false;
                }
                foreach (string str in subKeyNames)
                {
                    if (str.StartsWith("MSSQL."))
                    {
                        using (RegistryKey key2 = key.OpenSubKey(str, false))
                        {
                            string str2 = (string)key2.GetValue("", "");
                            if (str2 == "PERFECT")
                            {
                                return true;
                            }
                        }
                    }
                }
            }
            return false;
        }

        private void myLogon_Error(object sender, string message)
        {
            if (base.InvokeRequired)
            {
                MyLogon.ErrorEventHander method = new MyLogon.ErrorEventHander(this.myLogon_Error);
                base.Invoke(method, new object[] { sender, message });
            }
            else
            {
                XtraMessageBox.Show("Kh\x00f4ng thể tạo được cơ sở dữ liệu\nChi tiết:\n\t" + message, "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                this.wcFirstRun.SelectedPage = this.wpLogin;
            }
        }

        private void myLogon_Fail(object sender)
        {
            if (base.InvokeRequired)
            {
                MyLogon.FailEventHander method = new MyLogon.FailEventHander(this.myLogon_Fail);
                base.Invoke(method, new object[] { sender });
            }
            else
            {
                base.DialogResult = XtraMessageBox.Show("Kh\x00f4ng thể tạo được cơ sở dữ liệu tự động!\nĐể phần mềm hoạt động cần thiết lập cơ sở dữ liệu!\nBạn muốn xem Video hướng dẫn hay thử lại với một c\x00e1ch kh\x00e1c.\nNếu chọn Yes để xem, chọn No để kết th\x00fac ứng dụng.", "Th\x00f4ng B\x00e1o", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                if (base.DialogResult == DialogResult.Yes)
                {
                    FileInfo info = new FileInfo(Application.StartupPath + @"\SetupSQL.wmv");
                    if (info.Exists)
                    {
                        Process.Start(info.FullName);
                    }
                }
                else if (base.DialogResult == DialogResult.No)
                {
                    Environment.Exit(0);
                }
            }
        }

        private void myLogon_Finish(object sender, string connecstring)
        {
            new MyLogon().SaveConfig(this.cbxServer.Text, this.rdgAuthentication.SelectedIndex, this.teLogin.Text, this.tePassword.Text, this.txtDatabase.Text);
        }

        private void MyLogonFirst(object sender, string connectString, string database)
        {
            if (base.InvokeRequired)
            {
                MyLogon.FirstEventHander method = new MyLogon.FirstEventHander(this.MyLogonFirst);
                base.Invoke(method, new object[] { sender, connectString, database });
            }
            else
            {
                this.wcFirstRun.SelectedPage = this.wpComplete;
                this.autoCreate.Active = false;
                this._exit = false;
                if (!Directory.Exists(Application.StartupPath + @"\Layout"))
                {
                    Directory.CreateDirectory(Application.StartupPath + @"\Layout");
                }
                if (!Directory.Exists(Application.StartupPath + @"\Data"))
                {
                    Directory.CreateDirectory(Application.StartupPath + @"\Data");
                }
                SqlHelper.ConnectString = connectString;
                new SqlHelper(connectString).Extract();
                //new XfmCompany(true, 1, connectString).ShowDialog(this);
                //base.Close();
            }
        }

        private void rdgAuthentication_SelectedIndexChanged(object sender, EventArgs e)
        {
            bool disable = this.rdgAuthentication.SelectedIndex == 0;
            this.DisableSQLServerAuthentication(disable);
        }

        private void RemoveFormCloseButton()
        {
            SkinElement element = FormSkins.GetSkin(UserLookAndFeel.Default)[FormSkins.SkinFormButtonClose];
            element.Image.Image = null;
            element.Glyph.Image = null;
        }

        private void wcFirstRun_CancelClick(object sender, CancelEventArgs e)
        {
            Environment.Exit(0);
        }

        private void wcFirstRun_NextClick(object sender, WizardCommandButtonClickEventArgs e)
        {
            if (e.Page != this.wpSelects)
            {
                if (e.Page == this.wpLogin)
                {
                    if (this.chxManual.Checked)
                    {
                        if (this.IsConnecttion(this.cbxServer.Text, "master", this.teLogin.Text, this.tePassword.Text))
                        {
                            this.wcFirstRun.SelectedPage = this.wpLogin;
                        }
                        else
                        {
                            this.wcFirstRun.SelectedPage = this.wpSelects;
                        }
                    }
                    else if (this.chxClient.Checked)
                    {
                        if (this.IsConnecttion(this.cbxServer.Text, "master", this.teLogin.Text, this.tePassword.Text))
                        {
                            this.wcFirstRun.SelectedPage = this.wpCreate;
                        }
                        else
                        {
                            this.wcFirstRun.SelectedPage = this.wpSelects;
                        }
                    }
                }
                else if (e.Page == this.wpCreate)
                {
                    if (this.chxManual.Checked | this.chxAuto.Checked)
                    {
                        this.wcFirstRun.SelectedPage = this.wpClient;
                        this.Auto();
                    }
                }
                else if (e.Page == this.wpAuto)
                {
                    if (!this.chxClient.Checked)
                    {
                        this.Auto();
                    }
                    else
                    {
                        if (this.cbxDatabase.Text == "")
                        {
                            this.wcFirstRun.SelectedPage = this.wpCreate;
                            XtraMessageBox.Show("Cở Sở Dữ Liệu chưa x\x00e1c định.", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        if (this.IsConnecttion(this.cbxServer.Text, this.cbxDatabase.Text, this.teLogin.Text, this.tePassword.Text))
                        {
                            MyLogon logon = new MyLogon();
                            logon.SaveConfig(this.cbxServer.Text, this.rdgAuthentication.SelectedIndex, this.teLogin.Text, this.tePassword.Text, this.cbxDatabase.Text);
                            this.wcFirstRun.SelectedPage = this.wpComplete;
                        }
                        else
                        {
                            this.wcFirstRun.SelectedPage = this.wpCreate;
                        }
                    }
                }
                else if ((e.Page == this.wpClient) && this.chxClient.Checked)
                {
                    if (this.cbxDatabase.Text == "")
                    {
                        this.wcFirstRun.SelectedPage = this.wpCreate;
                        XtraMessageBox.Show("Cở Sở Dữ Liệu chưa x\x00e1c định.", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else if (this.IsConnecttion(this.cbxServer.Text, this.cbxDatabase.Text, this.teLogin.Text, this.tePassword.Text))
                    {
                        this.wcFirstRun.SelectedPage = this.wpComplete;
                        new MyLogon().SaveConfig(this.cbxServer.Text, this.rdgAuthentication.SelectedIndex, this.teLogin.Text, this.tePassword.Text, this.cbxDatabase.Text);
                    }
                    else
                    {
                        this.wcFirstRun.SelectedPage = this.wpCreate;
                    }
                }
            }
            else if (!this.chxAuto.Checked)
            {
                if ((!this.chxManual.Checked && !this.chxClient.Checked) && this.chxPerfect.Checked)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    this.Demo();
                    Cursor.Current = Cursors.Default;
                }
            }
            else
            {
                Cursor.Current = Cursors.WaitCursor;
                if (!this.IsExpressInstalled())
                {
                    switch (XtraMessageBox.Show("M\x00e1y t\x00ednh chưa c\x00e0i đặt Microsoft SQL Server 2005.\nVui l\x00f2ng xem hướng dẫn c\x00e1ch c\x00e0i đặt.\nNếu chọn Yes để xem, chọn No để thử lại v\x00e0 chọn Cancel để kết th\x00fac ứng dụng.", "Th\x00f4ng B\x00e1o", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation))
                    {
                        case DialogResult.Yes:
                            {
                                FileInfo info = new FileInfo(Application.StartupPath + @"\SetupSQL.wmv");
                                if (info.Exists)
                                {
                                    Process.Start(info.FullName);
                                }
                                break;
                            }
                        case DialogResult.No:
                            this.chxManual.Checked = true;
                            this.chxAuto.Checked = false;
                            this.wcFirstRun.SelectedPage = this.wpSelects;
                            return;

                        case DialogResult.Cancel:
                            Environment.Exit(0);
                            break;
                    }
                }
                this.Auto();
                Cursor.Current = Cursors.Default;
            }
        }

        private void wcFirstRun_PrevClick(object sender, WizardCommandButtonClickEventArgs e)
        {
            if (e.Page == this.wpLogin)
            {
                this.wcFirstRun.SelectedPage = this.wpSelects;
            }
            else if (e.Page == this.wpClient)
            {
                this.wcFirstRun.SelectedPage = this.wpCreate;
            }
        }

        private void wcFirstRun_SelectedPageChanged(object sender, WizardPageChangedEventArgs e)
        {
        }

        private void wcFirstRun_SelectedPageChanging(object sender, WizardPageChangingEventArgs e)
        {
        }

        private void xfmFirstRunConfig_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this._exit)
            {
                Environment.Exit(0);
            }
        }

        private void xfmFirstRunConfig_Load(object sender, EventArgs e)
        {
        }
    }

}
